package com.lyncs.ods;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.util.unit.DataSize;

import javax.servlet.MultipartConfigElement;

/**
 * @author alex
 */
@SpringBootApplication
@EnableTransactionManagement
@EnableScheduling
@EnableAsync
@Configuration
public class OdsApplication {

    @Value("${spring.servlet.multipart.max-file-size:50MB}")
    private String maxFileSize;
    @Value("${spring.servlet.multipart.max-request-size:50MB}")
    private String maxRequestSize;

    public static void main(String[] args) {
        SpringApplication.run(OdsApplication.class, args);
    }

    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        factory.setMaxRequestSize(DataSize.parse(maxFileSize));
        factory.setMaxFileSize(DataSize.parse(maxRequestSize));
        return factory.createMultipartConfig();
    }

}
